package com.makan;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.ServletContext;
import java.io.IOException;
import java.util.jar.Manifest;

@Controller
@RequestMapping("/")
public class HelloController {

    @Autowired
    private ServletContext servletContext;

	@RequestMapping(method = RequestMethod.GET)
	public String printWelcome(ModelMap model) throws IOException {
        Manifest mf = new Manifest(servletContext.getResourceAsStream("/META-INF/MANIFEST.MF"));

        String appName = mf.getMainAttributes().getValue("app-name");
        String appVersion = mf.getMainAttributes().getValue("app-version");
        String appBuildDate = mf.getMainAttributes().getValue("app-build-date");

        model.addAttribute("appName", appName);
        model.addAttribute("appVersion", appVersion);
        model.addAttribute("appBuildDate", appBuildDate);
		model.addAttribute("message", "Hello world!");
		return "hello";
	}
}